package com.zhaojun.cloud.z.view.controller.view;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.zhaojun.cloud.common.net.HttpUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * wwj
 * 2018/11/29  16:59
 */
@Controller
@RequestMapping("/im")
public class ImViewController {

    @RequestMapping
    public String index() {
        return "im/index";
    }

    @RequestMapping("/welcome")
    public String welcome(HttpServletRequest request, Model model) throws Exception {
        String resultString = HttpUtil.doGet("http://127.0.0.1:8031/zhaojun-service-im/welcome");
        ObjectMapper objectMapper = new ObjectMapper();
        Map result = objectMapper.readValue(resultString, Map.class);
        model.addAllAttributes(result);
        return "im/welcome";
    }

    @RequestMapping("/userOnline")
    public String userOnline() {
        return "im/user";
    }


    @RequestMapping("/chat")
    public String chat() {
        return "im/chat";
    }

    @RequestMapping("/broadcasting")
    public String broadcasting() {
        return "im/broadcasting";
    }

}
